<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');

if (!function_exists('domain')) {
	function domain($s)
	{
		if (preg_match('/^([a-zA-z]+:\\/\\/)([^\\s^\\/]*)\\/?$/', $s, $arr)) {
			return $arr[2];
		}
	}
}

if (!function_exists('idno')) {
	function idno($s)
	{
		return preg_replace_callback('/^[0-9]{2}([0-9]*)[0-9]{2}$/', function($match) {
			return str_replace($match[1], '*********', $match[0]);
		}, $s);
	}
}

if (!function_exists('email')) {
	function email($s)
	{
		return preg_replace_callback('/^\\S{3}(\\S*)@\\S+$/', function($match) {
			return str_replace($match[1], '****', $match[0]);
		}, $s);
	}
}

if (!function_exists('mobile')) {
	function mobile($s)
	{
		return preg_replace_callback('/^[0-9]{3}([0-9]*)[0-9]{4}$/', function($match) {
			return str_replace($match[1], '****', $match[0]);
		}, $s);
	}
}

if (!function_exists('get_stat')) {
	function get_stat($v)
	{
		if ($v['status'] == 0) {
			$d['stat'] = 1;
			$d['name'] = '未提交';
		}
		else if ($v['status'] == 1) {
			$d['stat'] = 2;
			$d['name'] = '待审核';
		}
		else {
			if (($v['status'] == 2) && ($v['begin'] <= time()) && (time() < $v['end'])) {
				$d['stat'] = 3;
				$d['name'] = '进行中';
			}
			else {
				if (($v['status'] == 2) && ($v['end'] <= time()) && ($v['target_amount'] <= $v['deal'])) {
					$d['stat'] = 4;
					$d['name'] = '已成功';
				}
				else {
					if (($v['status'] == 2) && (time() < $v['begin'])) {
						$d['stat'] = 5;
						$d['name'] = '即将开始';
					}
					else {
						if (($v['status'] == 2) && ($v['end'] <= time()) && ($v['deal'] < $v['target_amount'])) {
							$d['stat'] = 6;
							$d['name'] = '失败';
						}
						else if ($v['status'] == 3) {
							$d['stat'] = 7;
							$d['name'] = '未通过';
						}
					}
				}
			}
		}
	}
}

if (!function_exists('error_404')) {
	function error_404()
	{
		echo '<script>location.href="/error404.html"</script>';
		exit();
	}
}

?>
